package com.codeoss.module.test.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.codeoss.module.test.model.TestTest1;
import com.codeoss.module.test.service.ITestTest1Service;

@Controller
@RequestMapping("rest/test")
public class RestTestController {
	@Autowired
	private ITestTest1Service testTest1Service;
	
	@RequestMapping(value = "dataSearch", method = RequestMethod.POST)
	@ResponseBody
	public RestTestResponse dataSearch(){
		RestTestResponse restTestResponse=new RestTestResponse();
		List<TestTest1> data=testTest1Service.list();
		restTestResponse.setData(data);
		return restTestResponse;
	}
	
	@RequestMapping(value = "dataInsert", method = RequestMethod.POST)
	@ResponseBody
	public RestTestResponse dataInsert(@RequestBody TestTest1 testTest1){
		RestTestResponse restTestResponse=new RestTestResponse();
		testTest1Service.insert(testTest1);
		List<TestTest1> data=new ArrayList<TestTest1>();
		data.add(testTest1);
		restTestResponse.setData(data);
		return restTestResponse;
	}
	
	@RequestMapping(value = "dataUpdate", method = RequestMethod.POST)
	@ResponseBody
	public RestTestResponse dataUpdate(@RequestBody TestTest1 testTest1){
		RestTestResponse restTestResponse=new RestTestResponse();
		testTest1Service.update(testTest1);
		List<TestTest1> data=new ArrayList<TestTest1>();
		data.add(testTest1);
		restTestResponse.setData(data);
		return restTestResponse;
	}
	
	@RequestMapping(value = "dataDelete", method = RequestMethod.POST)
	@ResponseBody
	public RestTestResponse dataDelete(@RequestBody TestTest1 testTest1){
		RestTestResponse restTestResponse=new RestTestResponse();
		testTest1Service.delete(testTest1);
		return restTestResponse;
	}
}
